package com.itheima.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

public class Demo3Servlet extends HttpServlet {


    private ServletConfig servletConfig;

    @Override
    public void init(ServletConfig config) throws ServletException {
        this.servletConfig=config;
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String encoding = servletConfig.getInitParameter("encoding");
        System.out.println(encoding);
        System.out.println("------------");
        Enumeration<String> names = servletConfig.getInitParameterNames();
        while (names.hasMoreElements()){
            String name = names.nextElement();
            String parameter = servletConfig.getInitParameter(name);
            System.out.println(name+"--------->"+parameter);
        }
        System.out.println("-----------------");
        String servletName = servletConfig.getServletName();
        System.out.println(servletName);
        System.out.println("-----------------");
        ServletContext servletContext = servletConfig.getServletContext();
        System.out.println(servletContext);
        System.out.println("----------");
        Object attribute = servletContext.getAttribute("url");
        System.out.println(attribute);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
/*
doget 与dopost的get与post获取，发送
声明，映射
/代表全部？/*呢
 */